/**
 * File:bc.fun
 * Youth is just a section of unoptimized code!
 * -------------------------------------------------------------------------
 * Created by BigQ on 2016/11/8.
 *--------------------------------------------------------------------------
 * This technical information is confidential information,
 * without my written permission is prohibited for commercial purposes.　
 *--------------------------------------------------------------------------
 */
(function (a) {
    var b = function (e) {
        if (typeof e != "object" || !e.content) {
            return false
        }
        var d = document.createElement("textarea");
        var c = "";
        var f = e.content;
        if (typeof f == "string") {
            c = f
        }
        if (typeof f == "object") {
            c = JSON.stringify(f)
        }
        if (typeof f == "function") {
            c = f.toString()
        }
        d.value = c;
        d.style.width = "1px";
        d.style.height = "1px";
        document.body.appendChild(d);
        d.select();
        if (document.execCommand("Copy")) {
            document.body.removeChild(d);
            e.success && typeof e.success == "function" && e.success(c)
        } else {
            e.error && typeof e.error == "function" && e.error()
        }
    };
    if (a.jQuery && typeof a.jQuery == "function" && typeof jQuery.prototype.extend == "function") {
        jQuery.fn.extend({
            copy: function (c) {
                if (!c.success || typeof c.success != "function") {
                    c.success = new Function()
                }
                if (!c.error || typeof c.error != "function") {
                    c.error = new Function()
                }
                if (c.selector && !c.content) {
                    $(this).click(function () {
                        var d = $(c.selector).html() || $(c.selector).val();
                        b({content: d, success: c.success, error: c.error})
                    })
                } else {
                    if (!c.selector && c.content) {
                        $(this).click(function () {
                            var d = c.content;
                            b({content: d, success: c.success, error: c.error})
                        })
                    } else {
                        return false
                    }
                }
            }
        })
    }
    a.textCopy = b
})(window);